﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using Shop.Model;
using Shop.Framework.Services;
using System.Web.Mvc;

namespace Shop.Framework.Page {
    public class CMS_CategoryPage:ViewPage {
        
        public List<Category> CategoryList { get; set; }
        public Category CategoryInView { get; set; }

        protected override void OnInit(EventArgs e) {
            try {
                CategoryService service = new CategoryService();
                
                CategoryList = service.GetCategories();
                var found = ViewData["CategoryInView"] as Category;

                CategoryInView = found == null ? CategoryList.FirstOrDefault() : CategoryList.FirstOrDefault( c => found.IdCategory == c.IdCategory);
                //if (CategoryInView == null)
                //    CategoryInView = CategoryList.First();

            } catch (Exception ex) {
                throw new Exception("CMS CMS_CategoryPage error.", ex);
            }
            base.OnInit(e);
        }        
    }
}
